/*
 * The default style sheet used to render MathML (MathMLCore enabled).
 *
 * Copyright (C) 2014 Google Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

@namespace "http://www.w3.org/1998/Math/MathML";

/* Default display */
* {
    display: block math;
    font-size: math;
}

/* By default, we only display the MathML formulas without any formatting other than the one specified by the display attribute. */
math {
    direction: ltr;
    writing-mode:  horizontal-tb;
    text-indent: 0;
    letter-spacing: normal;
    line-height: normal;
    word-spacing: normal;
    font-family: math;
    font-size: inherited;
    font-style: normal;
    font-weight: normal;
    display: inline math;
    math-shift: normal;
    math-style: compact;
    font-size: inherited;
    math-depth: 0;
}

math[display="block"] {
    display: block math;
    text-align: center;
}

:-internal-spatial-navigation-interest {
    outline: auto 1px -webkit-focus-ring-color;
    box-shadow: none !important;
}

:focus {
    outline: auto 1px -webkit-focus-ring-color;
}

mspace {
    overflow: hidden !important;
}

/* <mrow>-like elements */
semantics > :not(:first-child) {
  display: none;
}

merror {
    border: 1px solid red;
    background-color: lightYellow;
}

mphantom {
    visibility: hidden;
}

/* Token elements */
mi {
  text-transform: math-auto;
}

/* Tables */
mtable {
  math-style: compact;
  display: inline-table;
}

mtr {
  display: table-row;
}

mtd {
  display: table-cell;
  padding: 0.5ex 0.4em;
  /* TODO(crbug.com/1125111): Properly center complex <mtd> children like mrow. */
  text-align: -webkit-center;
}

/* Fractions */
mfrac {
  padding-inline-start: 1px;
  padding-inline-end: 1px;
}

mfrac > * {
  math-depth: auto-add;
  math-style: compact;
}

mfrac > :nth-child(2) {
  math-shift: compact;
}

/* Other rules for scriptlevel, displaystyle and math-shift */
mroot > :not(:first-child) {
    math-depth: add(2);
    math-style: compact;
}
mroot, msqrt {
    math-shift: compact;
}
msub > :not(:first-child),
msup > :not(:first-child),
msubsup > :not(:first-child),
mmultiscripts > :not(:first-child),
munder > :not(:first-child),
mover > :not(:first-child),
munderover > :not(:first-child) {
  math-depth: add(1);
  math-style: compact;
}

munder[accentunder="true" i] > :nth-child(2),
mover[accent="true" i] > :nth-child(2),
munderover[accentunder="true" i] > :nth-child(2),
munderover[accent="true" i] > :nth-child(3) {
  font-size: inherit;
}
msub > :nth-child(2),
msubsup > :nth-child(2),
mmultiscripts > :nth-child(even),
mmultiscripts > mprescripts ~ :nth-child(odd),
mover[accent="true" i] > :first-child,
munderover[accent="true" i] > :first-child {
  math-shift: compact;
}
mmultiscripts > mprescripts ~ :nth-child(even) {
  math-shift: inherit;
}
